/****************************************************
          File Name:34-2.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun 31 Aug 2014 07:45:03 PM CST
*****************************************************/

#include<stdio.h>
#include<errno.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>

int main(int argc,char *argv[])
{
    pid_t pid;
    switch(pid=fork())
    {
        case -1:
            exit(EXIT_FAILURE);
        case 0:
            //sleep(10);
            if(execl("/bin/ls","ls","-l",(char *)0)==-1)
            {
                perror("execl");
                exit(1);
            }
            
            break;
        default:
            sleep(2);
            setpgid(pid,0);
            if(errno)
            {
                perror("setpgid");
            }
            printf("OK\n");
            sleep(30);
            break;
    }

    exit(0);
}
